using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using UnityEngine;

namespace Elvex
{
    public enum CryptographicHash
    {
        //MD4,
        MD5 = 1,
    }

    public static class FileUtility
    {
        public static string GetCryptographicHash(this FileInfo file, CryptographicHash method)
        {
            switch(method)
            {
                case CryptographicHash.MD5:
                    return GetMD5Hash(file);
                default:
                    return "";
            }
        }

        public static string GetMD5Hash(this FileInfo file)
        {
            FileStream fs = file.OpenRead();
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] retVal = md5.ComputeHash(fs);
            fs.Close();
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < retVal.Length; i++)
            {
                builder.Append(retVal[i].ToString("x2"));
            }
            return builder.ToString();
        }
    }
}

